package idiet.dao.hibernate;

import idiet.bean.CustomerNurse;
import idiet.bean.CustomerNurseMeal;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("customerNurseMealDao")
public class CustomerNurseMealDao extends BaseDao {
	public CustomerNurseMeal getCustomerNurseMealById(int customerNurseMealId){
		return (CustomerNurseMeal) this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMeal.class)
				.add(Restrictions.eq("id", customerNurseMealId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerNurseMeal> getCustomerNurseMealsByCustomerNurseMealName(String name){
		return  this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMeal.class)
				.add(Restrictions.like("name",name))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerNurseMeal> getCustomerNurseMeals(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMeal.class)
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerNurseMeal> getCustomerNurseMealsByCustomerNurse(CustomerNurse nurse){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMeal.class)
				.add(Restrictions.eq("customerNurse", nurse))
				.list();
	}
	public void createCustomerNurseMeal(CustomerNurseMeal customerNurseMeal){
		this.sessionFactory
		.getCurrentSession()
		.save(customerNurseMeal);
	}
	public void updateCustomerNurseMeal(CustomerNurseMeal customerNurseMeal){
		this.sessionFactory
		.getCurrentSession()
		.update(customerNurseMeal);
	}
	public void deleteCustomerNurseMeal(CustomerNurseMeal customerNurseMeal){
		this.sessionFactory
		.getCurrentSession()
		.delete(customerNurseMeal);
	}
}
